package com.ubhave.powertracker;

import java.util.Date;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.wifi.WifiManager;
import android.os.BatteryManager;
import android.preference.PreferenceManager;
import android.util.Log;
import android.widget.Toast;

//This doesn't actually fire or work yet - catching display state changes isn't as simple as other broadcast recievers.
public class DisplayStateChangeBroadcastReciever extends BroadcastReceiver{

	@Override
	public void onReceive(Context context, Intent intent) {
				
		String type="unknown";
		
		if(intent.getAction().equals("android.intent.action.ACTION_SCREEN_ON"))
			type="On";
		else if(intent.getAction().equals("android.intent.action.ACTION_SCREEN_OFF"))
			type="Off";
		
		Log.i("POWeR Tracker Sensor: ", "Display State Event "+type);
		
		//Toast.makeText(PowerTrackerApplication.getContext(), "POWeR Tracker Power State. "+type, Toast.LENGTH_SHORT).show();
		
		
		SharedPreferences settings;
		settings=PreferenceManager.getDefaultSharedPreferences(PowerTrackerApplication.getContext());
		
		if(settings.getBoolean("SensorsOn", false)){
			SharedPreferences.Editor editor = settings.edit();
			editor.putString("sensorLog", settings.getString("sensorLog", "")+"Push Sensor: DisplayStateChanged("+type+") "+"TimeStamp("+new Date()+"), ");
        	editor.commit();
		}
				
	}
	
	
	
}